/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bmechat.gui;

import java.util.List;
import javax.swing.JTextArea;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import bmechat.client.Client;

/**
 *
 * @author david
 */
public class ChatLogArea extends JTextArea implements ChangeListener{

    private Client client;
    private int lastMessageShown = -1;

    public ChatLogArea(Client client){
        super("Welcome to BME-Chat!\n");
        this.client = client;
        setEditable(false);
        client.addChatLogListener(this);
    }

    public void stateChanged(ChangeEvent e) {
        List<String> chatLog = client.getChatLog();
        this.setText("");
        for(String s : chatLog){
            this.append(s + "\n");
        }
        this.setCaretPosition(this.getDocument().getLength());
    }

}
